

set(CMAKE_SYSTEM_NAME Generic)

# tool chain set
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
    set(ARM_TOOLCHAIN_PATH "C:/toolchain/arm-none-eabi/bin")
    set(CMAKE_C_COMPILER    ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-gcc.exe)
    set(CMAKE_CXX_COMPILER  ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-gcc.exe)
    set(CMAKE_ASM_COMPILER  ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-gcc.exe)
    set(CMAKE_LINKER        ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-gcc.exe)
    set(CMAKE_OBJCOPY       ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-objcopy.exe)
    set(CMAKE_SIZE          ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-size.exe)
    set(CMAKE_OBJDUMP       ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-objdump.exe)
    # set(TO_NATIVE_PATH ${ARM_TOOLCHAIN_PATH} NATIVE_ARM_TOOLCHAIN_PATH)
    file(TO_NATIVE_PATH  "${PROJECT_SOURCE_DIR}/tool/cmake" TOOL_PATH)
    set(ENV{PATH} "$ENV{PATH};${TOOL_PATH}")
elseif ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
    set(ARM_TOOLCHAIN_PATH "/usr/bin")
    set(CMAKE_C_COMPILER    ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-gcc)
    set(CMAKE_CXX_COMPILER  ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-gcc)
    set(CMAKE_ASM_COMPILER  ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-gcc)
    set(CMAKE_LINKER        ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-gcc)
    set(CMAKE_OBJCOPY       ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-objcopy)
    set(CMAKE_SIZE          ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-size)
    set(CMAKE_OBJDUMP       ${ARM_TOOLCHAIN_PATH}/arm-none-eabi-objdump)
else()
    message(FATAL_ERROR "platform error: ${CMAKE_HOST_SYSTEM_NAME}, only support Windows or Linux")
endif()

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(CMAKE_EXECUTABLE_SUFFIX_C   .elf)
set(CMAKE_EXECUTABLE_SUFFIX_CXX .elf)
set(CMAKE_EXECUTABLE_SUFFIX_ASM .elf)

set(CMAKE_C_FLAGS "" CACHE INTERNAL "C compiler flags")
set(CMAKE_ASM_FLAGS "" CACHE INTERNAL "ASM compiler flags")
set(CMAKE_EXE_LINKER_FLAGS "" CACHE INTERNAL "Exe linker flags")

# search for program/library/include in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(COMMON_FLAGS
    -mcpu=arm926ej-s
    -msoft-float
    -O0 -Wall
    -fmessage-length=0
    -fsigned-char
    -ffunction-sections
    -fdata-sections
    CACHE INTERNAL "build common flags"
)
